package com.example.demotest.demos.bens;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.FileOutputStream;

public class WordExample {
    public static void main(String[] args) {
        try {
            // 创建一个空的Word文档
            XWPFDocument document = new XWPFDocument();

            // 创建一个段落
            XWPFParagraph paragraph = document.createParagraph();
            XWPFRun run = paragraph.createRun();

            // 设置文本
            run.setText("Hello, World!");

            // 将文档写入到磁盘上的文件中
            FileOutputStream out = new FileOutputStream("HelloWorld.docx");
            document.write(out);
            out.close();

            System.out.println("Word文档已创建！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}